package ph.com.isla.sf2d;


public abstract class SF2DGameLoop implements Runnable {
	private SF2DSurfaceView mSurface;
	private Thread gameThread;
	private volatile boolean stopLoop = false;

	public SF2DGameLoop(SF2DSurfaceView surface) {
		this.mSurface = surface;
		if (mSurface != null){
			mSurface.setInGameLoop(true);
		}
		gameThread = new Thread(this);
		onCreate(surface);
	}

	public void start() {
		gameThread.start();
	}
	
	public void stop(){
		stopLoop = true;
	}

	@Override
	public void run() {
		while (!stopLoop) {
			moveSprites(mSurface);
			mSurface.invalidate();
			checkResults();
		}
		
		onDestroy();
	}
	

	public abstract void moveSprites(SF2DSurfaceView surface);
	public abstract void onCreate(SF2DSurfaceView surface);
	public abstract void checkResults();
	public abstract void onDestroy();
}
